'''
Author: Ryan
Email: 409266255@qq.com
Date: 2025-09-03 17:36:09

LastEditors: Ryan
LastEditTime: 2025-09-12 18:10:16
Description: 头部注释

FilePath: /quant_python/main.py
Copyright (c) 2025 by Ryan, All Rights Reserved. 
'''


import qlib
from qlib.constant import REG_CN
from qlib.data import D


def main():
    print("Hello from quant-python!")


#   【Sample】获取数据测试 
def get_data():
    provider_uri = "~/.qlib/qlib_data/cn_data/"
    qlib.init(provider_uri=provider_uri, region=REG_CN)
    instruments = D.instruments(market="all")
    fields = ["$open", 
              "$high", 
              "$low", 
              "$close", 
              "adjclose", 
              "$factor",
              "$change",
              "$volume",
              "$vwap",
              "$total_turnover"]
    data = D.features(instruments=instruments, start_time="2025-09-01", end_time="2025-09-11", fields=fields, freq="day")
    print(data)


#   【Sample】获取具体股票数据
def get_security_data():
    provider_uri = "~/.qlib/qlib_data/cn_data/"
    qlib.init(provider_uri=provider_uri, region=REG_CN)
    fields = ["$close", 
              "$adjclose",
              "$factor",
              "$change",
              "$open", 
              "$high", 
              "$low", 
              "$volume",
              "$vwap",
              "$total_turnover"]
    data = D.features(["sh603527"], start_time="2025-09-07", end_time="2025-09-11", fields=fields, freq="day")
    print(data)


if __name__ == "__main__":
    # main()
    # get_data()
    get_security_data()
